import React from 'react';
import {inject, observer} from 'mobx-react';
import {Button, Modal, Spin, Row, Col, Input, Radio, Checkbox} from 'antd';
import {
  WeaNewScroll,
  WeaTop,
  WeaRightMenu,
  WeaTab,
  WeaSearchGroup,
  WeaInput,
  WeaSelect,
  WeaDialog,
  WeaTimePicker,
  WeaDatePicker,
  WeaCheckbox,
  WeaFormItem,
  WeaInputNumber,
  WeaLocaleProvider
} from 'ecCom';
import {Form} from 'antd';
import {WeaSwitch} from 'comsMobx'
import {toJS} from 'mobx';
import AlertModal from './AlertModal';
import * as MultiOptions from './constants/MultiOptions';
import SwitchFormField from './SwitchFormField';
import NoRight from '../NoRight'

const SmallGup = () => (<span style={{display: 'inline-block', width: 4}}></span>);
const LargeGup = () => (<span style={{display: 'inline-block', width: 12}}></span>);
const getLabel = WeaLocaleProvider.getLabel;

// @inject('comsWeaTableStore')
@inject('planModulStore')
@observer
class AddWorkModel extends React.Component {
  
  state = {};

  componentDidMount() {
    const planModulStore = this.props.planModulStore;
    planModulStore.initAddWorkPlanFormFields();
  }

  componentWillUnmount() {
  }

  saveModulePlan = () =>{
    const {planModulStore} = this.props,
    addWorkPlanFormParams = planModulStore.getAddWorkPlanFormParams(),
    addWorkPlanFormOtherParams = toJS(planModulStore.addWorkPlanFormOtherParams);

    const {isremind, remindBeforeStart, remindBeforeEnd, timeModul,immediatetouch} = addWorkPlanFormOtherParams;
    const timeModulKeys = MultiOptions.regularModeOptions().map((elem) => elem.key);

    const alertFunc = () => AlertModal(getLabel(384146,'必要信息不完整，红色*号为必填项！'));

    const alertFunc4endDate = () => AlertModal(getLabel(389914,'立即触发，请选择有效结束日期！'));

    if (!addWorkPlanFormParams.name){
      alertFunc();
      return;
    }

    if (addWorkPlanFormParams['secretLevel']===''){
      alertFunc();
      return;
    }

    if (!addWorkPlanFormParams.principal) {
      AlertModal(getLabel(2097,'负责人') + getLabel(21423,'未填写'));
      return;
    }

    if (isremind === 1 && remindBeforeStart === "0" && remindBeforeEnd === "0") {
      AlertModal(getLabel(20238,'日程提醒时间未被选定！'));
      return;
    }
  
    if (timeModul !== timeModulKeys[0]) {//定期模式
      const {beginDate, endDate,startTime} = addWorkPlanFormOtherParams;
      const {immediatetouch} = addWorkPlanFormParams;
      let {times,fer_0,fer_1,fer_2,fery,switchWeek} = addWorkPlanFormOtherParams;
      if (!startTime) {
        alertFunc()
        return;
      }
      
      //选择周
      if(timeModul === timeModulKeys[2]&&!fer_0){//选择周
        alertFunc()
        return;
      }else if(timeModul === timeModulKeys[3]&&switchWeek=='0'&&!fer_1){//选择月
        alertFunc()
        return;
      }else if(timeModul === timeModulKeys[4]&&(!fer_2||(switchWeek=='0'&&!fery))){//选择年
        alertFunc()
        return;
      }
      

      if(!times || times == ''){//持续时间
        alertFunc();
        return;
      }

      if(!beginDate || beginDate == ''){//有效期
        alertFunc();
        return;
      }
      if(immediatetouch=='1'){//立即触发，结束日期为必填
          if(!endDate || endDate == ''){
              alertFunc4endDate();
              return;
          }
      }
      if (beginDate > endDate) {
        AlertModal(getLabel(83347,'结束日期不能小于开始日期'));
        return;
      }
    }
    planModulStore.doSave();
  }

  cancelModulePlan = () =>{
    const {planModulStore} = this.props;
    planModulStore.closeAddDialog();
  }

  getRightMenu = () => {
    const { planModulStore } = this.props;
    const { hasRight } = this.props.planModulStore;
    
    let btnArr = [];
    btnArr.push({
      key: 'save',
      content: getLabel(30986,'保存'),
      icon: <i className='icon-coms-Preservation' />,
      onClick: this.saveModulePlan,
    },{
      key: 'cancel',
      content: getLabel(201,'取消'),
      icon: <i className='icon-coms-edit' />,
      onClick: this.cancelModulePlan,
    })
    
    return btnArr;
  }

  render() {
    const {planModulStore} = this.props;
    let {hasRight}=planModulStore;
    return (
      <div>
        {hasRight?
        (<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@gnn9u1`}
          icon="icon-coms-schedule"
          iconBgcolor="#7734FF"
          title={getLabel(18220,'计划工作模板')}
          className='wea-workplan-addworkmodal'
          visible={planModulStore.ifShowAddDialog}
          onCancel={() => {
            planModulStore.closeAddDialog()
          }}
          hasScroll="true"
          style={{width: 785, height: 564}}
          buttons={[
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@j8s3mp@doSave`}
              type={"primary"}
              loading={planModulStore.saveLoading}
              onClick={() => {
                const {planModulStore} = this.props,
                  addWorkPlanFormParams = planModulStore.getAddWorkPlanFormParams(),
                  addWorkPlanFormOtherParams = toJS(planModulStore.addWorkPlanFormOtherParams);

                const {isremind, remindBeforeStart, remindBeforeEnd, timeModul,immediatetouch} = addWorkPlanFormOtherParams;
                const timeModulKeys = MultiOptions.regularModeOptions().map((elem) => elem.key);

                const alertFunc = () => AlertModal(getLabel(384146,'必要信息不完整，红色*号为必填项！'));

                const alertFunc4endDate = () => AlertModal(getLabel(389914,'立即触发，请选择有效结束日期！'));

                if (!addWorkPlanFormParams.name){
                  alertFunc();
                  return;
                }

                if (addWorkPlanFormParams['secretLevel']===''){
                  alertFunc();
                  return;
                }

                if (!addWorkPlanFormParams.principal) {
                  AlertModal(getLabel(2097,'负责人') + getLabel(21423,'未填写'));
                  return;
                }

                if (isremind === 1 && remindBeforeStart === "0" && remindBeforeEnd === "0") {
                  AlertModal(getLabel(20238,'日程提醒时间未被选定！'));
                  return;
                }
               
                if (timeModul !== timeModulKeys[0]) {//定期模式
                  const {beginDate, endDate,startTime} = addWorkPlanFormOtherParams;
                  const {immediatetouch} = addWorkPlanFormParams;
                  let {times,fer_0,fer_1,fer_2,fery,switchWeek} = addWorkPlanFormOtherParams;
                  if (!startTime) {
                    alertFunc()
                    return;
                  }
                  
                  //选择周
                  if(timeModul === timeModulKeys[2]&&!fer_0){//选择周
                    alertFunc()
                    return;
                  }else if(timeModul === timeModulKeys[3]&&switchWeek=='0'&&!fer_1){//选择月
                    alertFunc()
                    return;
                  }else if(timeModul === timeModulKeys[4]&&(!fer_2||(switchWeek=='0'&&!fery))){//选择年
                    alertFunc()
                    return;
                  }
                  

                  if(!times || times == ''){//持续时间
                    alertFunc();
                    return;
                  }

                  if(!beginDate || beginDate == ''){//有效期
                    alertFunc();
                    return;
                  }
                  if(immediatetouch=='1'){//立即触发，结束日期为必填
                      if(!endDate || endDate == ''){
                          alertFunc4endDate();
                          return;
                      }
                  }
                  if (beginDate > endDate) {
                    AlertModal(getLabel(83347,'结束日期不能小于开始日期'));
                    return;
                  }
                }
                planModulStore.doSave();
              }}
            >
              {getLabel(30986,'保存')}
            </Button>,
            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@pe02oi@doCancel`}
              onClick={() => {
                planModulStore.closeAddDialog();
              }}
            >
              {getLabel(201,'取消')} 
            </Button>
          ]}
        >
          
          <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@f7nl6p`} 
            datas={this.getRightMenu()}
            collectParams={{
              favname: getLabel(27911,'周期日程'),
              favouritetype: 2,
              objid: 0,
              importantlevel: 1,
            }}
            >
            <div style={{overflow:'auto',height:'100%'}}>
              <div className={'add-work-model'}>
                {/* <WeaNewScroll height={564}> */}
                  {this.getAddWorkPlanForm()}
                {/* </WeaNewScroll> */}
              </div>
            </div>
          </WeaRightMenu>

        </WeaDialog>)
        :(<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@eu3gfw`}
          icon="icon-coms-schedule"
          iconBgcolor="#7734FF"
          title={getLabel(18220,'计划工作模板')}
          className='wea-workplan-addworkmodal'
          visible={planModulStore.ifShowAddDialog}
          onCancel={() => {
            planModulStore.closeAddDialog()
          }}
          style={{width: 785, height: 564}}
        >
          <div className={'add-work-model'}>
            {/* <WeaNewScroll height={564}> */}
              <NoRight ecId={`${this && this.props && this.props.ecId || ''}_NoRight@uru5by`}/>
            {/* </WeaNewScroll> */}
          </div>
        </WeaDialog>)
        }
      </div>
    )
  };
  // 获取计划工作模板表单
  getAddWorkPlanForm = () => {
    const WeaFormItem = Form.Item;
    const planModulStore = this.props.planModulStore;
    const {addWorkPlanForm, addWorkPlanFormConditionInfo,ifHideSomeAboutFieldObj:{ifHideRemindType} } = planModulStore;
    const {isFormInit} = addWorkPlanForm;
    const conditioninfo = toJS(addWorkPlanFormConditionInfo);
    let group = [];
    // 获取表单的值
    const formParams = addWorkPlanForm.getFormParams();

    //用于根据store的一些属性来控制表单中几个相关xx字段的显隐
    //以及负责这些字段的正确渲染
    //ifHideKey,表示store中用于取得hide的值的相应key
    function setSomeAboutField(ifHideKey, items, fields, weaForm, store, formParams) {
      items.push({
        com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@wzn0vk@${fields.domkey[0]}`}
          label={`${fields.label}`}
          labelCol={{span: `${fields.labelcol}`}}
          wrapperCol={{span: `${fields.fieldcol}`}}>
          {/*根据 WeaSwitch 获取对应的组件*/}
          <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@8m2hnb@${fields.domkey[0]}`} fieldConfig={fields} form={weaForm} formParams={formParams}/>
        </WeaFormItem>),
        colSpan: 1,
        hide: store.ifHideSomeAboutFieldObj[ifHideKey]
      })
    }
    // isFormInit 为true，form已经初始化完成
    isFormInit && conditioninfo.map((c, _index) => {
      let items = [];
      c.items.map(fields => {
        if (fields.domkey[0] === 'custome') {//日程提醒时间
          items.push(this.getReminderTimeForm(fields));
        } else if (fields.domkey[0] === 'timeModul') {//定期模式
          items.push(this.getRegularModeForm(fields));
        } else if (fields.domkey[0] === 'times') {//持续时间
          items.push(this.getDurationForm(fields));
        } else if (fields.domkey[0] === 'deadTime') {//有效期
          items.push(this.getValidPeriod(fields));
        } else if (fields.domkey[0] === 'immediatetouch') {//立即触发
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@fqbqk4@${fields.domkey[0]}`}
              label={`${fields.label}`}
              labelCol={{span: `${fields.labelcol}`}}
              wrapperCol={{span: `${fields.fieldcol}`}}>
              {/*根据 WeaSwitch 获取对应的组件*/}
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@habihs@${fields.domkey[0]}`} fieldConfig={fields} form={addWorkPlanForm} formParams={formParams}/>
            </WeaFormItem>),
            colSpan: 1,
            hide: this.getIfHide()
          })
        } else if (fields.domkey[0] === 'docid') {//相关文档
          setSomeAboutField("ifHideReletedDoc", items, fields, addWorkPlanForm, planModulStore, formParams);
        } else if (fields.domkey[0] === 'requestid') {//相关流程
          setSomeAboutField("ifHideReletedWF", items, fields, addWorkPlanForm, planModulStore, formParams);
        } else if (fields.domkey[0] === 'crmid') {//相关客户
          setSomeAboutField("ifHideReletedcrm", items, fields, addWorkPlanForm, planModulStore, formParams);
        } else if (fields.domkey[0] === 'projectid') {//相关项目
          setSomeAboutField("ifHideReletedProject", items, fields, addWorkPlanForm, planModulStore, formParams);
        } else if (fields.domkey[0] === 'taskid') {//相关任务
          setSomeAboutField("ifHideReletedTask", items, fields, addWorkPlanForm, planModulStore, formParams);
        } else if (fields.domkey[0] === 'secretLevel') {//密级
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@fqbqk4@${fields.domkey[0]}`}
              label={`${fields.label}`}
              labelCol={{span: `${fields.labelcol}`}}
              wrapperCol={{span: `${fields.fieldcol}`}}>
              {/*根据 WeaSwitch 获取对应的组件*/}
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@habihs@${fields.domkey[0]}`} fieldConfig={fields} form={addWorkPlanForm} formParams={formParams} onChange={this.onChange.bind(this)}/>
            </WeaFormItem>),
            colSpan: 1,
          })
          
        } else if (fields.domkey[0] === 'submiter') {//提交人
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@o3zkpm@${fields.domkey[0]}`}
              label={`${fields.label}`}
              labelCol={{span: `${fields.labelcol}`}}
              wrapperCol={{span: `${fields.fieldcol}`}}
              className={'submiter'}
            >
              {/*根据 WeaSwitch 获取对应的组件*/}
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@co9p91@${fields.domkey[0]}`} fieldConfig={fields} form={addWorkPlanForm} formParams={formParams}/>
            </WeaFormItem>),
            colSpan: 1,
          })
        } else if (fields.domkey[0] === 'principal') {//负责人
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@1ytwj6@${fields.domkey[0]}`}
              label={`${fields.label}`}
              labelCol={{span: `${fields.labelcol}`}}
              wrapperCol={{span: `${fields.fieldcol}`}}
              className={'principal'}
            >

              {/*根据 WeaSwitch 获取对应的组件*/}
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@aqmz6j@${fields.domkey[0]}`} fieldConfig={fields} form={addWorkPlanForm} formParams={formParams}/>
            </WeaFormItem>),
            colSpan: 1,
          })
        } else {
          if(fields.domkey[0] === 'remindType' && ifHideRemindType) return;
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@o15mx7@${fields.domkey[0]}`}
              label={`${fields.label}`}
              labelCol={{span: `${fields.labelcol}`}}
              wrapperCol={{span: `${fields.fieldcol}`}}>
              {/*根据 WeaSwitch 获取对应的组件*/}
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@ltzs3m@${fields.domkey[0]}`} fieldConfig={fields} form={addWorkPlanForm} formParams={formParams}/>
            </WeaFormItem>),
            colSpan: 1,
          })
        }

      });
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@ml7ilq@${_index}`} needTigger={false} showGroup={c.defaultshow} items={items} col={1}/>)
    });
    return group;
  };

  getReminderTimeForm(fields) {
    const FormItem = Form.Item;
    const {addWorkPlanForm, setAddWorkPlanFormOtherParams, addWorkPlanFormOtherParams} = this.props.planModulStore;

    //这段代码是根据日程提醒方式的值来控制日程提醒时间的显隐
    let addWorkPlanFormParams = addWorkPlanForm.getFormParams();
    let reminderModeFieldVal = addWorkPlanFormParams.remindType;
    setAddWorkPlanFormOtherParams("isremind", reminderModeFieldVal == 1 || reminderModeFieldVal == '' ? 0 : 1);

    return {
      com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@0zn6qz`}
        label={`${fields.label}`}
        labelCol={{span: `${fields.labelcol}`}}
        wrapperCol={{span: 18}}
        className='wea-workplan-addworkmodal-notetime'
      >
        <div style={{marginBottom: 10}}>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@tyudnz`}
            component={WeaCheckbox}
            attrname={"remindBeforeStart"}
            style={{marginRight: 10}}
          />
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@d99sya`}></SmallGup>
          {/*<Checkbox onChange={(value)=>{return null;}} />*/}
          <span>{getLabel(19784,'开始前')}</span>
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@un80h5`}></SmallGup>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@arrzl0`}
            component={WeaInputNumber}
            attrname={"remindDateBeforeStart"}
            style={{width: 78}}
          />
          {/*<WeaInput onChange={(value)=>{return null;}} style={{width:'50px'}}/>*/}
          <span style={{margin: '0 4px'}}>{getLabel(391,'小时')}</span>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@m8a1ss`}
            component={WeaInputNumber}
            attrname={"remindTimeBeforeStart"}
            style={{width: 78}}
          />
          {/*<WeaInput onChange={(value)=>{return null;}} style={{width:'50px'}}/>*/}
          <span style={{margin: '0 50px 0 4px'}}>{getLabel(15049,'分钟')}</span>
        </div>

        <div>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@pjyw0x`}
            component={WeaCheckbox}
            attrname={"remindBeforeEnd"}
            style={{marginRight: 10}}
          />
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@lalupv`}></SmallGup>
          {/*<Checkbox onChange={(value)=>{return null;}} />*/}
          <span>{getLabel(19785,'结束前')}</span>
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@4pbu45`}></SmallGup>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@d5ahen`}
            component={WeaInputNumber}
            attrname={"remindDateBeforeEnd"}
            style={{width: 78}}
          />
          {/*<WeaInput onChange={(value)=>{return null;}} style={{width:'50px'}}/>*/}
          <span style={{margin: '0 4px'}}>{getLabel(391,'小时')}</span>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@f840sw`}
            component={WeaInputNumber}
            attrname={"remindTimeBeforeEnd"}
            style={{width: 78}}
          />
          {/*<WeaInput onChange={(value)=>{return null;}} style={{width:'50px'}}/>*/}
          <span style={{margin: '0 0 0 4px'}}>{getLabel(15049,'分钟')}</span>
        </div>

      </WeaFormItem>),
      colSpan: 1,
      hide: (addWorkPlanFormOtherParams.get("isremind") === 0 ? true : false)
    }
  }

  //生成定期模式字段上的表单控件
  getRegularModeForm(fields) {
    const FormItem = Form.Item;
    return {
      com: (<FormItem ecId={`${this && this.props && this.props.ecId || ''}_FormItem@d5lvkj`}
        label={`${fields.label}`}
        labelCol={{span: `${fields.labelcol}`}}
      >

        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@ub5bxw`} span={18} className={'regularForm'}>
          <span>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@xxib7k`}
              component={WeaSelect}
              attrname={"timeModul"}
              options={MultiOptions.regularModeOptions()}
            />
          </span>
          {this.getFormAfterRegularModeSelect()}
        </Col>

      </FormItem>),
      colSpan: 1,
    }
  }


  //定期模式字段中的第一个选择框选择了之后，此方法决定该字段后面的表单是什么
  getFormAfterRegularModeSelect = () => {
    const {planModulStore} = this.props;
    const timeModul = planModulStore.addWorkPlanFormOtherParams.get("timeModul");

    const timeModulKeys = MultiOptions.regularModeOptions().map((elem) => elem.key);


    switch (timeModul) {

      case timeModulKeys[0]:
        return null;
        break;

      case timeModulKeys[1]:
        return (
          <span>
            <LargeGup ecId={`${this && this.props && this.props.ecId || ''}_LargeGup@cgo2xi`}/>
            <span>{getLabel(21977,'每')}</span>
            <div style={{width:50,display: 'inline-block'}}>
              <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@27bbv6`} component={WeaInputNumber} attrname={"interval"} defaultValue={1} min={1} />
            </div>
            <span>{getLabel(1925,'天')}</span>
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@hwmuwu`}/>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@rt8rac`}
              component={WeaTimePicker}
              noInput={true}
              attrname={"startTime"}
              viewAttr={3}
            />
          </span>
        );
        break;

      case timeModulKeys[2]:
        return (
          <span >
            <LargeGup ecId={`${this && this.props && this.props.ecId || ''}_LargeGup@pngdnf`}></LargeGup>
            <span>{getLabel(21977,'每')}</span>
            <div style={{width:50,display: 'inline-block'}}>
              <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@t2jziz`} component={WeaInputNumber} attrname={"interval"} defaultValue={1} min={1} />
            </div>
            <span>{getLabel(1926,'周')}</span>
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@lj2vxl`}></SmallGup>      
          
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@c6ltiu`} 
              component={WeaSelect}
              multiple
              viewAttr={3}
              attrname={"fer_0"} 
              options={MultiOptions.optionsOfSelectAWeekDay()} 
              />
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@9rddbg`}></SmallGup>
            <span>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@y925z2`}
              component={WeaTimePicker}
              noInput={true}
              attrname={"startTime"}
              viewAttr={3}
              />
            </span>
          </span>
        );
        break;

      case timeModulKeys[3]:
        return (
          <span>
            <LargeGup ecId={`${this && this.props && this.props.ecId || ''}_LargeGup@xws9b8`}></LargeGup>
            <span>{getLabel(21977,'每')}</span>
            <div style={{width:50,display: 'inline-block'}}>
              <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@pnh3es`} component={WeaInputNumber} attrname={"interval"} defaultValue={1} min={1}/>
            </div>
            <span>{getLabel(6076,'月')}</span>
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@6xwrzr`}></SmallGup>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@17u2dx`}
              component={WeaSelect}
              attrname={"switchWeek"}
              options={MultiOptions.optionsOfSwitchWeek()}
              />
             {planModulStore.addWorkPlanFormOtherParams.get("switchWeek")==1?
             (<span>
                  <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@g0o66y`}></SmallGup>
                    <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@u35v0w`}
                    component={WeaSelect}
                    attrname={"fer_3"}
                    options={MultiOptions.optionsOfWeekIndex()}
                    />
                    <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@pkh4ar`}></SmallGup>
                    <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@tlobv9`}
                    component={WeaSelect}
                    attrname={"fer_0"}
                    options={MultiOptions.optionsOfSelectAWeekDay()}
                    />
             
              </span>):
             (<span>
                  <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@azn15e`}></SmallGup>
                  <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@bl41gs`}
                    component={WeaSelect}
                    attrname={"monthType"}
                    options={MultiOptions.optionsOfSelectAOrder()}
                    />
                  <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@coek6z`}></SmallGup>
                  <span>{getLabel(15323,'第')}</span>
                  <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@7c60l5`}></SmallGup>
                  <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@79unmn`} 
                    component={WeaSelect}
                    multiple
                    viewAttr={3}
                    attrname={"fer_1"} 
                    options={MultiOptions.optionsOfSelectAMonthDay} 
                  />
                  <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@loy194`}></SmallGup>
                  <span>{getLabel(1925,'天')}</span>
              </span>)
            }
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@m6gmrw`}></SmallGup>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@6mv1dt`}
                component={WeaTimePicker}
                noInput={true}
                attrname={"startTime"}
                viewAttr={3}
  
            />
             
            
          </span>
        );
        break;

      case timeModulKeys[4]:
        return (
          <span>
            <LargeGup ecId={`${this && this.props && this.props.ecId || ''}_LargeGup@vzgh6k`}></LargeGup>
            <span>{getLabel(21977,'每')}</span>
            <div style={{width:50,display: 'inline-block'}}>
              <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@e42xeo`} component={WeaInputNumber} attrname={"interval"} defaultValue={1} min={1}/>
            </div>
            <span>{getLabel(445,'年')}</span>
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@i67uoz`}></SmallGup>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@0trkon`}
              multiple
              viewAttr={3}
              component={WeaSelect}
              attrname={"fer_2"}
              options={MultiOptions.optionsOfSelectAMonth}
            />
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@f7ju5i`}></SmallGup>
            <span>{getLabel(6076,'月')}</span>
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@ufkrrw`}></SmallGup>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@w396qc`}
              component={WeaSelect}
              attrname={"switchWeek"}
              options={MultiOptions.optionsOfSwitchWeek()}
              />
            {planModulStore.addWorkPlanFormOtherParams.get("switchWeek")==1?
            (<span>
                <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@orynbe`}></SmallGup>
                  <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@wo60dt`}
                  component={WeaSelect}
                  attrname={"fer_3"}
                  options={MultiOptions.optionsOfWeekIndex()}
                  />
                  <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@sni2w3`}></SmallGup>
                  <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@q7p2ci`}
                  component={WeaSelect}
                  attrname={"fer_0"}
                  options={MultiOptions.optionsOfSelectAWeekDay()}
                  />
            </span>)
            :(<span>
                <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@zaq9yx`}></SmallGup>
                <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@ca3284`}
                  component={WeaSelect}
                  attrname={"yearType"}
                  options={MultiOptions.optionsOfSelectAOrder()}
                />
                <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@478ttg`}></SmallGup>
                <span>{getLabel(15323,'第')}</span>
                <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@hwu37t`}></SmallGup>
                <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@qozy3d`} 
                  component={WeaSelect}
                  multiple
                  viewAttr={3}
                  attrname={"fery"} 
                  options={MultiOptions.optionsOfSelectAMonthDay} 
                />
                <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@1tn7bd`}></SmallGup>
                <span>{getLabel(1925,'天')}</span>
            </span>)}
            <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@zvex5p`}></SmallGup>
            <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@xkvvon`}
              component={WeaTimePicker}
              noInput={true}
              attrname={"startTime"}
              viewAttr={3}
            />
          </span>
        );
        break;
    }
  }


  //用于控制持续时间、有效期字段、立即触发的表单域的显隐
  getIfHide() {
    const planModulStore = this.props.planModulStore;
    const timeModul = planModulStore.addWorkPlanFormOtherParams.get("timeModul");
    const ifHide = timeModul === "9" ? true : false;
    return ifHide;
  }

  //持续时间的表单
  getDurationForm(fields) {
    const FormItem = Form.Item;
    return {
      com: (<FormItem ecId={`${this && this.props && this.props.ecId || ''}_FormItem@8cb176`}
        label={`${fields.label}`}
        labelCol={{span: `${fields.labelcol}`}}
        className={'duration'}
      >
        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@jonmqj`} span={18} className={'durationForm'}>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@l5ka9q`}
            component={WeaInputNumber}
            attrname={"times"}
            style={{width: 78, height: 30}}
            viewAttr={3}
          />
          <LargeGup ecId={`${this && this.props && this.props.ecId || ''}_LargeGup@qdzvco`}></LargeGup>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@2rkwt4`}
            component={WeaSelect}
            attrname={"timeType"}
            options={MultiOptions.durationUnitOptions()}
          />
        </Col>
      </FormItem>),
      colSpan: 1,
      hide: this.getIfHide()
    }
  }

  //有效期的表单
  getValidPeriod(fields) {
    const FormItem = Form.Item;
    return {
      com: (<FormItem ecId={`${this && this.props && this.props.ecId || ''}_FormItem@0pemve`}
        label={`${fields.label}`}
        labelCol={{span: `${fields.labelcol}`}}
      >
        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@oilsh1`} span={18}>
          <span>{getLabel(348,'从')}</span>
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@8sbuwj`}></SmallGup>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@ld0ni2`}
            component={WeaDatePicker}
            attrname={"beginDate"}
            viewAttr={3}
          />
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@orsvsj`}></SmallGup>
          <span>{getLabel(15322,'至')}</span>
          <SmallGup ecId={`${this && this.props && this.props.ecId || ''}_SmallGup@smb90s`}></SmallGup>
          <SwitchFormField ecId={`${this && this.props && this.props.ecId || ''}_SwitchFormField@nxsf2d`}
            component={WeaDatePicker}
            attrname={"endDate"}
            viewAttr={2}
          />
        </Col>
      </FormItem>),
      colSpan: 1,
      hide: this.getIfHide()
    }
  }

  onChange = (paramsObj) => {
    let {addWorkPlanForm, setState , setOldSecretLevel,oldSecretLevel} = this.props.planModulStore;
    let params={};
    if (paramsObj.secretLevel) {//判断密级
      //密级等级是否小于当前使用等级
      const secretLevel = paramsObj['secretLevel'].value
      if(parseInt(secretLevel,10) > parseInt(oldSecretLevel,10)){
        let _that = this
        //清空文档和流程
        Modal.confirm({
          title: `${getLabel(131329,'信息确认')}`,
          content: `${getLabel(500701,'【密级】级别已更改且小于上次选择，文档、流程资源会被清空')}`,
          onOk() {
            //更新会议信息中的字段
            addWorkPlanForm.updateFields({
              docid: {
                value: '',
                valueSpan: '',
                valueObj: ''
              },
              requestid: {
                value: '',
                valueSpan: '',
                valueObj: ''
              },
              secretLevel:secretLevel
            })
            setOldSecretLevel(paramsObj['secretLevel'].value)
          },
          onCancel() {
            addWorkPlanForm.updateFields({
              secretLevel: {
                value: oldSecretLevel
              }
            })
          },
        });
      }else{
        setOldSecretLevel(paramsObj['secretLevel'].value)
      }
      
    }
  }

}

export default AddWorkModel;